﻿function DataPagingHttp() {
    var dataResult;

    var xmlHttp;
    this.createxmlHttpRequest = function () {
        if (window.ActiveXObject)
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        else if (window.XMLHttpRequest)
            xmlHttp = new XMLHttpRequest();
    };
    this.doRequestUsingGet = function (url) {
        this.createxmlHttpRequest();
        //var queryString = "/DataPaging/RequestAction.aspx?&timestamp=" + new Date().getTime();
        //queryString += actionStr;
        xmlHttp.open("GET", url);
        xmlHttp.onreadystatechange = this.handleStateChange;
        xmlHttp.send(null);
    };
    this.doRequestUsingPost = function (url, actionStr, dataResultFun) {
        dataResult = dataResultFun;
        this.createxmlHttpRequest();
        //var url = ;
        // var queryString = createQueryString();
        var queryString = actionStr;
        xmlHttp.open("POST", url);
        xmlHttp.onreadystatechange = this.handleStateChange;
        xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xmlHttp.send(queryString);
    };
    this.dataResult = function (data) {
        alert(data);
    };
    this.handleStateChange = function () {
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
            //alert(xmlHttp.responseText);
            dataResult(xmlHttp.responseText);
        }
    };
}

function DataPaging_OperatList() {
    var http = new DataPagingHttp();
    function DeleteTableTr(r) {
        var root = r.parentNode;
        root.deleteRow(r.rowIndex - 1);
    }
    function DeleteLi(index) {
        var s = document.getElementById('s');
        var t = s.childNodes.length;
        for (var i = t - 1; i > 0; i--) {
            if (i == n - 1) {
                s.removeChild(s.childNodes[i]);
            }
        }
    }
    
    this.DeleteData = function (id, funSuccess, funFail) {
        http.doRequestUsingPost("/ARSControl/Custom.aspx?control=TreeListView&timestamp=" + new Date().getTime(), "action=del&TableName={{TableName}}&ParentName={{ParentName}}&key={{keyField}}&id=" + id, function (data) {
            var json = JSON.parse(data);
            if (json.Code == 1) {
                if (funSuccess == undefined) {
                    var li = document.getElementById(id);
                    li.parentNode.removeChild(li);
                    //DeleteTableTr(r);
                } else {
                    funSuccess(data);
                }
            } else {
                if (funFail == undefined) {
                    alert(json.Remark);
                } else {
                    funFail(data);
                }
            }
        });
    };
}

var TreeListView_Operat = new DataPaging_OperatList();